home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows News 2010 Summer - Disc 1
/
WN_Ete2010_CD1.iso
/
Onglet5
/
Weezo
/
Weezo setup.exe
/
{code_appDir}
/
www
/
includes
/
layoutClass.php
< prev
next >
Wrap
PHP Script
|
2010-05-19
|
4KB
|
142 lines
<?php
define('layoutVertical', 0); // vertical panels
define('layoutHorizontal',1); // horizontal panels
define('layoutContent',2); // HTML content
/**
* HTML Layout class
*
*/
class layout{
private $id; // PHP & DOM id of block
private $type; // Layout type (layoutVertical || layoutHorizontal || layoutContent)
private $nbPanels; // number of pannels
public $parentLayout; // Parent layout (null if topmost layout)
private $userScalable; // True if user may shrink/expand this layout. Require a parent layout
private $dim; // width or height of layout depending on $type. Allowed values:
// 'auto': adapts on content
// 'fill': fills empty space left by other(s) panel(s)
// 'hidden': hidden
// numeric value in px, em or %
private $maxDim; // numeric value in px, em or %, false if no value
private $minDim; // numeric value in px, em or %, false if no value
private $extraStyle; // Extra CSS style to be applied
private $extraHTML; // Extra HTML (attributes) to be applied inside tag
public $content; // Content of layout: layout or HTML
/**
* @desc Constructor
*
* @param string $id: PHP & DOM element id
* @param int $type : layoutHorizontal or layoutVertical or layoutContent
* @param int $nbPanels : number of panels
*/
function __construct($id, $type, $nbPanels=0){
if($type!=layoutHorizontal && $type!=layoutVertical && $type!=layoutContent) throw new Exception('Incorrect layout type');
if($type==layoutContent) $nbPanels=0;
elseif (!is_numeric($nbPanels) || $nbPanels<2 || $nbPanels>3) throw new Exception('Incorrect number of panels (2 or 3)');
$this->type=$type;
$this->id=$id;
$this->nbPanels=$nbPanels;
$this->maxDim=false;
$this->minDim=false;
$this->userScalable=false;
$this->content=array();
$this->extraStyle='';
$this->extraHTML='';
$parentLayout=null;
}
/**
* @desc Set panel content
*
* @param int $panelNb: panel number
* @param mixed $content: HTML code or layout
*/
function setContent($content,$panelNb=0){
// HTML content
if($this->type==layoutContent && is_string($content)) $this->content=$content;
// Layout content
elseif(is_object($content) && get_class($content)=='layout') {
if($panelNb<0 || $panelNb >= $this->nbPanels) throw new Exception('Incorrect panel number');
$this->content[$panelNb]=$content;
$content->parentLayout=$this;
}
else throw new Exception('Incorrect content for '.$this->id.' '.$this->type);
}
/**
* @desc Set layout dimensions
*
* @param string $dim: See dim
* @param string $min: See min
* @param string $max: See max
*/
function setDimensions($dim, $min=false, $max=false){
if($dim!='auto' && $dim!='fill'){
if(is_numeric($dim)) $dim.='px';
if(substr($dim,-2)!='px' && substr($dim,-2)!='em' && substr($dim,-1)!='%') throw new Exception('Invalid dimension');
}
if($min>$max) throw new Exception('Invalid min/max values');
$this->dim=$dim;
$this->min=$min;
$this->max=$max;
}
/**
* @desc Set layout user scalable or not
*
* @param boolean $userScalable
*/
function setUserScalable($userScalable=true){
$this->userScalable=$userScalable;
}
function setExtraStyle($extraStyle){$this->extraStyle=$extraStyle;}
function setExtraHTML($extraHTML){$this->extraHTML=$extraHTML;}
/**
* @desc Create layouts : insert javascript and HTML code
*/
function create(){
if(!$this->parentLayout) {
$topMost=true;
$this->insertJavascript();
}
else $topMost=false;
echo '<div style="position:absolute;';
if ($this->type==layoutHorizontal){
echo 'width:'.(($this->dim=='fill')?'100%':$this->dim);
}
else{
echo 'height:'.(($this->dim=='fill')?'100%':$this->dim);
}
// Style
if($topMost) echo ';visibility:hidden';
echo (($this->extraStyle)?';'.$this->extraStyle:'').'"';
if($this->extraHTML) echo ' '.$this->extraHTML;
echo ' id="'.$this->id.'">';
// HTML content
if($this->type==layoutContent) {
echo $this->content;
}
// Other layouts
else for($i=0;$i<$this->nbPanels;$i++){
if(!isset($this->content[$i])) throw new Exception('Unset panel '.$i.' for layout '.$this->id);
$this->content[$i]->create();
}
echo "</div>\n";
}
function insertJavascript(){
}
}
?>